package archer.framework.protocol.result;

import jodd.json.meta.JSON;

/**
 * 系统执行结果包装类
 *
 * @author christ
 * @date 6/15/2015
 */
public class ExecuteResult {

    public ExecuteResult() {

        //empty
    }

    public ExecuteResult(String resultCode, String resultMsg) {

        this(resultCode, resultMsg, null);
    }

    public ExecuteResult(String resultCode, String resultMsg, Object resultData) {

        this(resultCode, resultMsg, null, resultData);
    }

    public ExecuteResult(String resultCode, String resultMsg, String resultCodeExt, Object resultData) {

        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.resultCodeExt = resultCodeExt;
        this.resultData = resultData;
    }

    public ExecuteResult(ResultCode resultCode) {

        this(resultCode.name(), resultCode.getMsg());
    }

    public ExecuteResult(ResultCode resultCode, String resultMsg) {

        this(resultCode.name(), resultMsg);
    }

    public ExecuteResult(ExecuteResult result) {

        this.resultCode = result.getResultCode();
        this.resultMsg = result.getResultMsg();
        this.resultData = result.getResultData();
        this.resultCodeExt = result.getResultCodeExt();
    }

    /**
     * code
     */
    private String resultCode;

    /**
     * code ext
     */
    private String resultCodeExt;

    /**
     * message
     */
    private String resultMsg;

    /**
     * data
     */
    private Object resultData;


    public String getResultCode() {

        return resultCode;
    }

    public ExecuteResult setResultCode(String resultCode) {

        this.resultCode = resultCode;
        return this;
    }

    public String getResultMsg() {

        return resultMsg;
    }

    public ExecuteResult setResultMsg(String resultMsg) {

        this.resultMsg = resultMsg;
        return this;
    }

    public Object getResultData() {

        return resultData;
    }

    public ExecuteResult setResultData(Object resultData) {

        this.resultData = resultData;
        return this;
    }

    public String getResultCodeExt() {

        return resultCodeExt;
    }

    public ExecuteResult setResultCodeExt(String resultCodeExt) {

        this.resultCodeExt = resultCodeExt;
        return this;
    }

    //---------------------------------for quick check---------------------------

    @JSON(include = false)
    public boolean isSuccess() {

        return ResultCode.SUCCESS.name().equals(getResultCode());
    }

    @JSON(include = false)
    public boolean isFail() {

        return !isSuccess();
    }

    @JSON(include = false)
    public boolean isTrue() {

        return ResultCode.TRUE.name().equals(getResultCode());
    }

    @JSON(include = false)
    public boolean isFalse() {

        return !isTrue();
    }
}
